package org.litu.app.constant;

import org.litu.core.base.BaseConstant;
import org.litu.util.common.SysMsgUtil;
import org.litu.util.file.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 系统常量
 *
 * @author yueye
 */
@Component
public class SysContant extends BaseConstant {

    /*-----------------------------系统业务相关内容------------------------------------*/

    /**
     * 角色岗位的枚举
     */
    public static final int ROLETYPE_ROLE = 1;
    public static final int ROLETYPE_STATION = 2;

    /**
     * 固定开始、结束时间查询参数名
     */
    public static final String QUERY_START_TIME = "startTime";
    public static final String QUERY_END_TIME = "endTime";

    /*-----------------------------系统框架相关内容------------------------------------*/

    /**
     * 菜单类型的静态变量，需要与字典值信息对应起来
     */
    public static final String MENUTYPE_MODULE = "module";
    public static final String MENUTYPE_FUNCTION = "function";
    public static final String MENUTYPE_BUTTON = "button";

    /**
     * 系统配置中，json数据类型的数据类型
     */
    public static final String CONFIG_TYPE_JSON = "json";

    /*-----------------------------系统配置相关内容------------------------------------*/

    /**
     * 日志输出时，当前系统的标识
     */
    public static String CURRENT_SYSTEM_CODE = "";

    @Value("${ltsystem.sysmsg.code}")
    public void setCurrentSystemCode(String systemCode) {
        SysContant.CURRENT_SYSTEM_CODE = systemCode;
    }

    /**
     * 文件存储目录,结尾需要带"/"
     */
    public static String FILE_BASE_PATH = "/file/";

    @Value("${ltsystem.file.basePath}")
    public void setFileBasePath(String fileBasePath) {
        String basePath = "";
        if (FileUtil.isAbsolutePath(fileBasePath)) {
            basePath = fileBasePath;
        } else {
            String rootPath = SysMsgUtil.jarPath();
            basePath = rootPath + "/" + fileBasePath;
        }
        // 保证文件目录结尾有斜线结束
        FILE_BASE_PATH = basePath + (basePath.endsWith("/") ? "" : "/");
    }

    /**
     * 文件存储目录，默认
     */
    public static String FILE_PATH_PATTERN = "YYYY-MM/";

    @Value("${ltsystem.file.pattern}")
    public void setFilePathPattern(String filePathPattern) {
        FILE_PATH_PATTERN = filePathPattern;
    }

    /**
     * 图片上传是否自动生成缩略图
     */
    public static Boolean THUMBNAIL_IMAGE = false;

    @Value("${ltsystem.file.thumbnailImage}")
    public void setThumbnailImage(boolean thumbnailImage) {
        THUMBNAIL_IMAGE = thumbnailImage;
    }
}
